package cn.rkylin.oms.system.supplier.domain;

import org.apache.commons.lang.StringUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;

public class SearchConditions {

    private boolean quickSearch;
    private String keyword;
    private List<String> enterpriseIds;
    private String code;
    private String name;
    private String remark;

    public boolean isQuickSearch() {
        return quickSearch;
    }

    public void setQuickSearch(boolean quickSearch) {
        this.quickSearch = quickSearch;
    }

    public String getKeyword() {
        return keyword;
    }

    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }

    public List<String> getEnterpriseIds() {
        return enterpriseIds;
    }

    public void setEnterpriseIds(List<String> enterpriseIds) {
        this.enterpriseIds = new ArrayList<>(enterpriseIds);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public void decode() {
        this.keyword = decodeParameter(this.keyword);
        this.code = decodeParameter(this.code);
        this.name = decodeParameter(this.name);
        this.remark = decodeParameter(this.remark);
    }

    private String decodeParameter(String value) {
        if (!StringUtils.isNotBlank(value)) {
            return null;
        }

        String decoded = null;
        try {
            decoded = URLDecoder.decode(value, "UTF-8");
        } catch (UnsupportedEncodingException ignore) {}

        return decoded;
    }
}
